#include "fig_exploding_gemini.h"

#include "num/rand.h"

FIGExplodingGemini::FIGExplodingGemini(FIGExploding::EXPLODING_TYPES Type) : FIGExploding(Type),
																			 m_Delay(0),
																			 m_Progress(0),																			 
																			 m_State(FIGExplodingGemini::GEMINI_STATE_NONE),
																			 m_RandomProgressScale(1.0f)
{
	m_Sprite.Create("gemini_explosion");
	//m_Sprite.Create("circle");
	m_Alpha = 1.0f;
	
}

FIGExplodingGemini::~FIGExplodingGemini()
{

}

void	FIGExplodingGemini::Render(const math::Vec2& Offset,float Scale)
{
	if(!m_IsAlive)
		return;

	if(m_Delay > 0)
	{
		return;
	}

	m_Sprite.m_Pos = m_Pos + Offset + m_RandomMovePos;
	m_Sprite.m_Size = m_Sprite.m_SizeOriginal * m_Scale * Scale * m_Progress;
	m_Sprite.m_Rotation = m_Rotation;
	m_Sprite.m_Color = ColorfRGBA(	0.98f * num::RAND32::Instance().RandFloat(0.5f,1.0f),
									0.5f * num::RAND32::Instance().RandFloat(0.5f,1.0f),
									0.16f * num::RAND32::Instance().RandFloat(0.5f,1.0f),
									m_Alpha * num::RAND32::Instance().RandFloat(0.9f,1.0f));
	m_Sprite.m_Additive = true;
	m_Sprite.RenderRotated();

}

void	FIGExplodingGemini::RenderDebug(const math::Vec2& Offset,float Scale)
{

}

void	FIGExplodingGemini::Tick(float dt)
{
	if(!m_IsAlive)
		return;

	if(m_Delay > 0)
	{
		m_Delay -= dt;
		return;
	}

	if( m_State == GEMINI_STATE_BIGGER)
	{
		m_Progress += dt * 6.0f;
		if(m_Progress >= 1.0f)
		{
			m_Progress = 1.0f;
			m_State = GEMINI_STATE_SMALLER;
		}
	}
	else if ( m_State == GEMINI_STATE_SMALLER)
	{
		m_Progress -= dt * 1.5f * m_RandomProgressScale;
		if(m_Progress <= 0)
		{
			m_Progress = 0;
			m_IsAlive = false;
		}
	}

	m_Sprite.Tick(dt);

}

void	FIGExplodingGemini::ReSpawn(	const math::Vec2& Pos,													
										float ScaleSize,
										float Rotation,
										float Delay
													)
{
	m_Progress = 0.0f;
	m_State = GEMINI_STATE_BIGGER;
	FIGExploding::ReSpawn(Pos, ScaleSize, Rotation,Delay);
	m_Delay = Delay;

	m_RandomProgressScale = num::RAND32::Instance().RandFloat(0.8f,1.2f);
	
}


